package com.zyh.pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author zyh
 * @Date 2024/8/12 14:50
 * @Description 自定义线程池
 */

public class ThreadPoolDemo6 {
    public static void main(String[] args) {
        //自定义线程池
        ThreadPoolExecutor executor=new ThreadPoolExecutor(
                1,
                2,
                10L,
                TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<Runnable>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        for (int i = 0; i < 7; i++) {
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"正在执行");
                }
            });
        }
        executor.shutdown();
    }
}
